#include <iostream>
#include <bits/stdc++.h>

using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    map<int, int> ref;
    map<int, int> counts;
    int index = 0;
    for (int i = 0; i < n; i++) {
        int v;
        cin >> v;
        counts[v]++;
    }
    for (const auto &item: counts) {
        ref[index] = item.first;
        index++;
    }
    //滑动窗口
    int l = 0;
    int r = 1;
    int sum = counts[ref[0]];
    int ans = sum;
    int len = 1;
    for (; r < index; r++) {
        if (ref[r] == ref[r - 1] + 1 && len + 1 <= k) {//可以滑动
            sum += counts[ref[r]];
            ans = max(ans, sum);
            len++;
            continue;
        }
        if (ref[r] == ref[r - 1] + 1) {
            sum = sum + counts[ref[r]] - counts[ref[l]];
            ans = max(ans, sum);
            l++;
            continue;
        }
        l = r;
        sum = counts[ref[r]];
        ans = max(ans, sum);
        len = 1;
    }

    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
